package com.wlk.controller;

import com.wlk.service.StudentsService;
import com.wlk.utils.Result;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@Controller
@RequestMapping("/students")
public class StudentsController {

    @Resource
    private StudentsService studentsService;
    /**
     * @description: 学生列表页面
     * @author:
     * @date: 2024/6/5 下午11:15
     * @param:
     * @return:
     **/

    @GetMapping("/student")
    public String students() {
        return "student";
    }

    /**
     * @description: 学生列表数据接口
     * @author:
     * @date: 2024/6/5 下午11:15
     * @param:
     * @return:
     **/
//    @GetMapping("/{page}/{size}")
//    @ResponseBody
//    public ModelAndView getStudentsPage(@PathVariable("page") Integer page, @PathVariable("size") Integer size, HttpRequest httpRequest) {
//        Result result = studentsService.getStudentsByPage(page, size);
//        ModelAndView modelAndView = new ModelAndView();
//        modelAndView.setViewName("student");
//        modelAndView.addObject("students", result.getData());
//        return modelAndView;
//    }
    @GetMapping("/{page}/{size}")
    @ResponseBody
    public Result getStudentsPage(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        return studentsService.getStudentsByPage(page, size);
    }

    @GetMapping("/import")
    public String importStudent() {
        return "import_students";
    }

    @PostMapping("/import")
    public String importStudents(@RequestParam("file") MultipartFile file) {
        studentsService.importStudents(file);
        // 重置到layoutPage

        return "redirect:/layoutPage";
    }
}
